﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using PccCommonForC;
using System.Data.SqlClient;
using System.Security.Cryptography;
using System.Text.RegularExpressions;
using System.Collections;
using System.Text;
using System.Collections.Generic;

namespace db_ShowRoom
{
    public class db_info : PccCommonForC.DbBaseObject
    {
        public db_info(): base(){}

        private string strcn;
        private SqlConnection cn;
        public db_info(string mconnect)
        {
            m_ConnectionString = mconnect;
            m_Conn = new SqlConnection(mconnect);
        }

        #region "db_InsUpdIntroduction "
        //Nguyen Huu Minh
       
        // InsUpdMenu
        public string db_InsUpdIntroduction(string strXML)
        {
            PccMsg myMsg = new PccMsg(strXML);
            string id_intro = myMsg.Query("id_intro").ToString().Trim();
            string content = myMsg.Query("content").ToString().Trim();
            string upd_id = myMsg.Query("upd_id").ToString().Trim();
            string myType = myMsg.Query("Type").ToString().Trim();
            if (id_intro == "")
                id_intro = "0";
            if (upd_id == "")
                upd_id = "0";
            SqlParameter[] parameters = { 
                                            new SqlParameter("@id_intro",SqlDbType.Int),  
                                            new SqlParameter("@content",SqlDbType.NText), 
                                            new SqlParameter("@upd_id",SqlDbType.Int),  
                                            new SqlParameter("@Type",SqlDbType.Char,1),
											new SqlParameter("@Err",SqlDbType.NVarChar,100)
										};

            parameters[0].Value = Convert.ToInt32(id_intro);
            parameters[1].Value = content;
            parameters[2].Value = upd_id;
            parameters[3].Value = myType;
            parameters[4].Direction = ParameterDirection.Output;

            try
            {
                int iReturn = 0, rowsAffected = 0;
                iReturn = RunProcedure("Pro_InsUpdIntro", parameters, ref rowsAffected);

                myMsg.ClearContext();

                myMsg.CreateFirstNode("ReturnValue", iReturn.ToString());
                myMsg.CreateFirstNode("RowsAffected", rowsAffected.ToString());
                myMsg.CreateFirstNode("Err", parameters[4].Value.ToString());
            }
            catch (Exception e)
            {
                myMsg.ClearContext();
                myMsg.CreateFirstNode("Err", e.Message.ToString());
            }

            return myMsg.GetXmlStr;
        }
        #endregion

        #region "Get Introduction"

        public DataSet db_Introduction(string strXML)
        {
            DataSet ds = new DataSet();
            PccMsg myMsg = new PccMsg(strXML);
            SqlParameter[] parameters = { 
                                          
										};
            ds = RunProcedure("Pro_GetIntroduction", parameters, "GetIntoduction");
            return ds;
        }
        #endregion

        #region "InsUpd img Slide"
        //Nguyen Huu Minh
        public string db_InsUpdImg(string strXML)
        {
            PccMsg myMsg = new PccMsg(strXML);
            string img_id = myMsg.Query("img_id").ToString().Trim();
            string img_name = myMsg.Query("img_name").ToString().Trim();
            string picture = myMsg.Query("picture").ToString().Trim();
            string active = myMsg.Query("active").ToString().Trim();
            string link_web = myMsg.Query("link_web").ToString().Trim();
            string user_id = myMsg.Query("user_id").ToString().Trim();
            string note = myMsg.Query("note").ToString().Trim();
            string myType = myMsg.Query("Type").ToString().Trim();
            if (img_id == "")
                img_id = "0";
            if (user_id == "")
                user_id = "0";
            SqlParameter[] parameters = { 
                                            new SqlParameter("@img_id",SqlDbType.Int),  
                                            new SqlParameter("@img_name",SqlDbType.NVarChar,50),             
                                            new SqlParameter("@picture",SqlDbType.NVarChar,100),                                         
                                            new SqlParameter("@active",SqlDbType.Char,1), 
                                            new SqlParameter("@link_web",SqlDbType.NVarChar,250), 
                                            new SqlParameter("@user_id",SqlDbType.Int), 
                                            new SqlParameter("@note",SqlDbType.NVarChar,2000), 
                                            new SqlParameter("@Type",SqlDbType.Char,1),
											new SqlParameter("@Err",SqlDbType.NVarChar,100)
										};

            parameters[0].Value = Convert.ToInt32(img_id);
            parameters[1].Value = img_name;
            parameters[2].Value = picture;
            parameters[3].Value = active;
            parameters[4].Value = link_web;
            parameters[5].Value = user_id;
            parameters[6].Value = note;
            parameters[7].Value = myType;
            parameters[8].Direction = ParameterDirection.Output;

            try
            {
                int iReturn = 0, rowsAffected = 0;
                iReturn = RunProcedure("Pro_InsUpdImgSlide", parameters, ref rowsAffected);

                myMsg.ClearContext();

                myMsg.CreateFirstNode("ReturnValue", iReturn.ToString());
                myMsg.CreateFirstNode("RowsAffected", rowsAffected.ToString());
                myMsg.CreateFirstNode("Err", parameters[8].Value.ToString());
            }
            catch (Exception e)
            {
                myMsg.ClearContext();
                myMsg.CreateFirstNode("Err", e.Message.ToString());
            }

            return myMsg.GetXmlStr;
        }
        #endregion

        #region "Get Img Slide Admin"
        public DataSet db_GetImgAdminBySearch(string strXML)
        {
            DataSet ds = new DataSet();
            PccMsg myMsg = new PccMsg(strXML);
            string img_id = myMsg.Query("img_id");
            string img_name = myMsg.Query("img_name");
            string active = myMsg.Query("active");
          
            if (img_id == "")
                img_id = "0";
            SqlParameter[] parameters = { 
                                          new SqlParameter("@img_id",SqlDbType.Int),  
                                          new SqlParameter("@img_name",SqlDbType.NVarChar,50),
                                          new SqlParameter("@active",SqlDbType.Char,1),
										};
            parameters[0].Value = img_id;
            parameters[1].Value = img_name;
            parameters[2].Value = active;
            ds = RunProcedure("Pro_GetImgSlideAdminBySearch", parameters, "GetLogoBySearch");
            return ds;
        }


        #endregion
    }
}
